{% extends 'default/base.html' %}  {% load static %}
{% block content %}
    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-lg-10">
            <h2>用户列表 | UserListView.</h2>
        </div>
        <div class="col-lg-2">
        </div>
    </div>

    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="ibox float-e-margins">
                <div class="panel-options">
                    <ul class="nav nav-tabs">
                        <li class="user_list"><a href="{% url 'user_list' %}" class="text-center"><i
                                class="fa fa-laptop"></i> 在职人员 </a></li>

                        <li class="disabled_user_list"><a href="{% url 'disabled_user_list' %}" class="text-center"><i
                                class="fa fa-bar-chart-o"></i> 禁用帐号</a></li>
                    </ul>
                </div>

                <div class="clearfix visible-xs-block"></div>

                <div class="ibox-content">
                    <table class="table table-bordered">
                        <thead>
                        <tr>
                            <th>用户名</th>
                            <th>部门</th>
                            <th>用户id</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        {% for user in user_list %}
                            <tbody>
                            <tr>
                                <td>{{ user.username }}</td>
                                <td>
                                    {% if user.department %}
                                        {{ user.department }}
                                    {% endif %}
                                </td>
                                <td>{{ user.id| add:30000 }}</td>
                                <td>
                                    {% if user.is_active %}
                                        <i class="fa fa-check-circle-o" style="color:#279048">正常</i>

                                    {% else %}
                                        <i class="fa fa-ban">禁用</i>
                                    {% endif %}</td>
                                <td>
                                    {% if request.user.is_superuser or request.session.fun_auth.edit_user %}
                                        <a href="{% url 'user_update' pk=user.pk %}" class="btn btn-xs btn-info">修改</a>
                                        {% if not user.is_active %}
                                            <a href="{% url 'change_user_active_status' pk=user.id %}"
                                               class="btn btn-success btn-xs status"></i>恢复</a>
                                        {% else %}
                                            <a href="{% url 'change_user_active_status' pk=user.id %}"
                                               class="btn btn-xs btn-warning status"></i>禁用</a>
                                        {% endif %}

                                    {% endif %}
                                </td>
                            </tr>
                            </tbody>
                        {% endfor %}
                    </table>

                <div class="row">
                    <div class="col-sm-6">
                         {% if request.user.is_superuser or request.session.fun_auth.edit_user %}
                            <a href="{% url 'user_register' %}" type="button" class="btn btn-info">添加用户</a>
                        {% endif %}
                    </div>
                </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        $(function () {
            $(document).on("click", ".status", function (e) {
                e.preventDefault();
                var url = $(this).attr("href");
                $.ajax({
                    type: "GET",
                    url: url
                }).done(function (data) {
                    window.location.reload();
                });
                return false;
            });
        })
    </script>
    <script type="text/javascript">
        var two = document.location.pathname.split("/")[2];
        $("." + two).addClass('active');
    </script>
{% endblock content %}
